import request from '@/utils/request'
const api = {
  getByIdForCache: '/api/xmbz-order/orderGroupLink/open/getByIdForCache',
  getisRange: '/api/xmbz-order/orderGroupLink/open/isRange',
  submitOrder: '/api/xmbz-order/orderGroupLink/open/v3/submitOrder',
  getOrderById: '/api/xmbz-order/orderGroupLink/open/v3/getOrderById',
  getpreSubmitOrder: '/api/xmbz-order/orderGroupLink/open/preSubmitOrder',
  upload: '/api/xmbz-goods/file/open/uploadBase64',
  getSelfDelivery: '/api/xmbz-order/orderGroupLink/open/getDeptList',
  getOrderList: '/api/xmbz-order/orderGroupLink/open/v3/getOrderList',
  getCaptcha: '/api/xmbz-order/orderGroupLink/open/phoneCaptcha',
  verifyCaptcha: '/api/xmbz-order/orderGroupLink/open/v3/verifyCaptcha',
  getConfig: '/api/xmbz-order/orderGroupLink/open/config',
  buried: '/api/xmbz-order/orderGroupLink/open/buried',
  getAssistant: '/api/xmbz-order/orderGroupLink/open/getAssistant',
}

export function getByIdForCache(params) {
  return request({
    url: api.getByIdForCache,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}
// H5获取自提城市列表
export function getSelfDelivery(params) {
  return request({
    url: api.getSelfDelivery,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}

export function getisRange(params) {
  // H5根据经纬度查询地址是否在配送范围
  return request({
    url: api.getisRange,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}
export function submitOrder(data) {
  // 根据城市ID获取自提地址列表
  return request({
    url: api.submitOrder,
    method: 'post',
    data,
    hideLoading: true // 隐藏 loading 组件
  })
}

export function getOrderById(params) {
  // H5根据城市ID获取渠道列表
  return request({
    url: api.getOrderById,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}
export function getpreSubmitOrder(data) {
  // H5预提交订单
  return request({
    url: api.getpreSubmitOrder,
    method: 'post',
    data,
  })
}
export function getCaptcha(params) {
  // H5预提交订单
  return request({
    url: api.getCaptcha,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}
export function Getupload(data) {
  // H5预提交订单
  return request({
    url: api.upload,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    hideLoading: true
  })
}
export function getOrderList(params) {
  // H5根据手机号查询团购列表
  return request({
    url: api.getOrderList,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}
export function setCookie(c_name, value, expiredays) {
  var exdate = new Date()

  exdate.setDate(exdate.getDate() + expiredays)

  document.cookie = c_name + '=' + value + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString())
}
export function getCookie(name) {
  var arr; var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  if (arr = document.cookie.match(reg)) {
   		return (arr[2])
  	} else {
    return false
  }
}
export function delCookie(name) {
 	var exp = new Date()
 	exp.setTime(exp.getTime() - 1)
 	var cval = getCookie(name)
 	if (cval) {
 	 	document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
 	}
}
export function verifyCaptcha(params) {
  // H5获取图形验证码
  return request({
    url: api.verifyCaptcha,
    method: 'get',
    params,
    hideLoading: true // 隐藏 loading 组件
  })
}

export function getConfig() {
  // 获取配置信息
  return request({
    url: api.getConfig,
    method: 'get',
    hideLoading: true // 隐藏 loading 组件
  })
}

export function buried(params) {
  // 获取配置信息
  return request({
    url: api.buried,
    method: 'get',
    hideLoading: true, // 隐藏 loading 组件
    params
  })
}

// 输入提示
export const getAssistant = (query) => {
  return request({
    url: api.getAssistant,
    method: 'get',
    params: query
  })
}
